package fileDemo.excel;

import org.apache.poi.ss.usermodel.Cell;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @function excel 读取 1行的样例，临时实体。
 */
public class PersonEntity {
    private List<String> mData;
    private String mTimeRule;
    private String mErrorStr;

    public PersonEntity(List<String> data) {
        if (data.size() >= ColumnsItems.MAX) {
            mData = data;
        } else {
            mData = new ArrayList<>();
        }
    }

    public PersonEntity(String[] data) {
        if (data.length >= ColumnsItems.MAX) {
            mData = new ArrayList<>();
            for (int i = 0; i <= ColumnsItems.MAX; i++) {
                if (i < ColumnsItems.MAX) {
                    mData.add(data[i]);
                } else {
                    if (data.length > ColumnsItems.MAX) {
                        mData.add((data[ColumnsItems.MAX]==null || data[ColumnsItems.MAX].length()==0) ? "" : data[ColumnsItems.MAX]);
                    }
                }
            }
        } else {
            mData = new ArrayList<>();
        }
    }

    public List<String> getData() {
        return mData;
    }

    public String getPassWord() {
        return mData.get(ColumnsItems.PASSWORD);
    }
    public String getJob() {
        return mData.get(ColumnsItems.JOB);
    }
    public String getComments() {
        return mData.get(ColumnsItems.COMMENTS);
    }

    public String getName() {
        return mData.get(ColumnsItems.NAME);
    }

    public String getUuid() {
        return mData.get(ColumnsItems.UUID);
    }

    public String getGroupId() {
        return mData.get(ColumnsItems.GROUP_ID);
    }

    public String getIcNumber() {
        return mData.get(ColumnsItems.IC_NUMBER);
    }

    public String getWgNumber() {
        return mData.get(ColumnsItems.WG_NUMBER);
    }

    public String getSex() {
        return mData.get(ColumnsItems.SEX);
    }

    public String getPhoneNumber() {
        return mData.get(ColumnsItems.PHONE);
    }

    public String getIdCard() {
        return mData.get(ColumnsItems.ID_CARD);
    }

    public String getMail() {
        return mData.get(ColumnsItems.MAIL);
    }

    public String getEntryDate() {
        return mData.get(ColumnsItems.ENTRY_DATA);
    }

    public String getOrganization() {
        return mData.get(ColumnsItems.ORGANIZATION);
    }

    public String getPhotoPath() {
        return mData.get(ColumnsItems.PHOTO_PATH);
    }

    public String getExtend1() {
        return mData.get(ColumnsItems.EXTEND_1);
    }

    public String getExtend2() {
        return mData.get(ColumnsItems.EXTEND_2);
    }

    public String getExtend3() {
        return mData.get(ColumnsItems.EXTEND_3);
    }

    public String getExtend4() {
        return mData.get(ColumnsItems.EXTEND_4);
    }

    public String getExtend5() {
        return mData.get(ColumnsItems.EXTEND_5);
    }

    public String getExtend6() {
        return mData.get(ColumnsItems.EXTEND_6);
    }

    public String getExtend7() {
        return mData.get(ColumnsItems.EXTEND_7);
    }

    public String getExtend8() {
        return mData.get(ColumnsItems.EXTEND_8);
    }

    public String getExtend9() {
        return mData.get(ColumnsItems.EXTEND_9);
    }

    public String getExtend10() {
        return mData.get(ColumnsItems.EXTEND_10);
    }

    public String getTimeRule() {
        return mTimeRule;
    }

    public String getErrorStr() {
        return mErrorStr;
    }

    public String getVerificationPassword() {
        if (mData.size() > ColumnsItems.MAX) {
            return mData.get(ColumnsItems.VERIFICATION_PASSWORD - 1);
        }
        return "";
    }

    public void setPassword(String password) {
        mData.add(ColumnsItems.PASSWORD, password);
    }

    public void setJob(String job) {
        mData.add(ColumnsItems.JOB, job);
    }

    public void setComments(String comments) {
        mData.add(ColumnsItems.COMMENTS, comments);
    }

    public void setName(String name) {
        mData.add(ColumnsItems.NAME, name);
    }

    public void setUuid(String uuid) {
        mData.add(ColumnsItems.UUID, uuid);
    }

    public void setGroupId(String groupId) {
        mData.add(ColumnsItems.GROUP_ID, groupId);
    }

    public void setIcNumber(String icNumber) {
        mData.add(ColumnsItems.IC_NUMBER, icNumber);
    }

    public void setWgNumber(String wgNumber) {
        mData.add(ColumnsItems.WG_NUMBER, wgNumber);
    }

    public void setSex(String sex) {
        mData.add(ColumnsItems.SEX, sex);
    }

    public void setPhoneNumber(String phoneNumber) {
        mData.add(ColumnsItems.PHONE, phoneNumber);
    }

    public void setIdCard(String idCard) {
        mData.add(ColumnsItems.ID_CARD, idCard);
    }

    public void setMail(String mail) {
        mData.add(ColumnsItems.MAIL, mail);
    }

    public void setEntryDate(String entryDate) {
        mData.add(ColumnsItems.ENTRY_DATA, entryDate);
    }

    public void setOrganization(String organization) {
        mData.add(ColumnsItems.ORGANIZATION, organization);
    }

    public void setPhotoPath(String photoPath) {
        mData.add(ColumnsItems.PHOTO_PATH, photoPath);
    }

    public void setExtend1(String extend1) {
        mData.add(ColumnsItems.EXTEND_1, extend1);
    }

    public void setExtend2(String extend2) {
        mData.add(ColumnsItems.EXTEND_2, extend2);
    }

    public void setExtend3(String extend3) {
        mData.add(ColumnsItems.EXTEND_3, extend3);
    }

    public void setExtend4(String extend4) {
        mData.add(ColumnsItems.EXTEND_4, extend4);
    }

    public void setExtend5(String extend5) {
        mData.add(ColumnsItems.EXTEND_5, extend5);
    }

    public void setExtend6(String extend6) {
        mData.add(ColumnsItems.EXTEND_6, extend6);
    }

    public void setExtend7(String extend7) {
        mData.add(ColumnsItems.EXTEND_7, extend7);
    }

    public void setExtend8(String extend8) {
        mData.add(ColumnsItems.EXTEND_8, extend8);
    }

    public void setExtend9(String extend9) {
        mData.add(ColumnsItems.EXTEND_9, extend9);
    }

    public void setExtend10(String extend10) {
        mData.add(ColumnsItems.EXTEND_10, extend10);
    }

    public void setTimeRule(String timeRule) {
        mTimeRule = timeRule;
    }

    public void setErrorStr(String errorStr) {
        mErrorStr = errorStr;
    }

    public void setVerificationPassword(String verificationPassword) {
        mData.add(ColumnsItems.VERIFICATION_PASSWORD, verificationPassword);
    }

    @Override
    public String toString() {
        return "PersonEntity{" +
                "name=" + mData.get(ColumnsItems.NAME) +
                ", UUID=" + mData.get(ColumnsItems.UUID) +
                ", libId=" + mData.get(ColumnsItems.GROUP_ID) +
                ", icNumber=" + mData.get(ColumnsItems.IC_NUMBER) +
                ", wgNumber=" + mData.get(ColumnsItems.WG_NUMBER) +
                ", sex=" + mData.get(ColumnsItems.SEX) +
                ", PhoneNumber=" + mData.get(ColumnsItems.PHONE) +
                ", idCard=" + mData.get(ColumnsItems.ID_CARD) +
                ", mail=" + mData.get(ColumnsItems.MAIL) +
                ", entryDate=" + mData.get(ColumnsItems.ENTRY_DATA) +
                ", organization=" + mData.get(ColumnsItems.ORGANIZATION) +
                ", photoPath=" + mData.get(ColumnsItems.PHOTO_PATH) +
                "password=" + mData.get(ColumnsItems.PASSWORD) +
                "job=" + mData.get(ColumnsItems.JOB) +
                "comments=" + mData.get(ColumnsItems.COMMENTS) +
                ", extend1=" + mData.get(ColumnsItems.EXTEND_1) +
                ", extend2=" + mData.get(ColumnsItems.EXTEND_2) +
                ", extend3=" + mData.get(ColumnsItems.EXTEND_3) +
                ", extend4=" + mData.get(ColumnsItems.EXTEND_4) +
                ", extend5=" + mData.get(ColumnsItems.EXTEND_5) +
                ", extend6=" + mData.get(ColumnsItems.EXTEND_6) +
                ", extend7=" + mData.get(ColumnsItems.EXTEND_7) +
                ", extend8=" + mData.get(ColumnsItems.EXTEND_8) +
                ", extend9=" + mData.get(ColumnsItems.EXTEND_9) +
                ", extend10=" + mData.get(ColumnsItems.EXTEND_10) +
                ", verificationPassword=" + mData.get(ColumnsItems.VERIFICATION_PASSWORD) +
                ", timeRule='" + mTimeRule + '\'' +
                ", errorStr='" + mErrorStr + '\'' +
                '}';
    }

    public static String getCellData(Cell cell) {
        if (cell == null) {
            return "";
        }
        if (cell.getColumnIndex() == ColumnsItems.ENTRY_DATA) {
            String timeStamp = cell.getDateCellValue().toString();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String formatDate = format.format(new Date(timeStamp));
            return formatDate;
        }
        cell.setCellType(Cell.CELL_TYPE_STRING);
        return cell.getStringCellValue();
    }

    public class ColumnsItems {
        public static final int NAME = 0;
        public static final int UUID = 1;
        public static final int PHOTO_PATH = 2;
        public static final int PASSWORD = 3;
        public static final int SEX = 4;
        public static final int ORGANIZATION = 5;
        public static final int MAIL = 6;
        public static final int PHONE = 7;
        public static final int IC_NUMBER = 8;
        public static final int WG_NUMBER = 9;
        public static final int ID_CARD = 10;
        public static final int GROUP_ID = 11;
        public static final int ENTRY_DATA = 12;
        public static final int JOB = 13;
        public static final int COMMENTS = 14;
        public static final int EXTEND_1 = 15;
        public static final int EXTEND_2 = 16;
        public static final int EXTEND_3 = 17;
        public static final int EXTEND_4 = 18;
        public static final int EXTEND_5 = 19;
        public static final int EXTEND_6 = 20;
        public static final int EXTEND_7 = 21;
        public static final int EXTEND_8 = 22;
        public static final int EXTEND_9 = 23;
        public static final int EXTEND_10 = 24;
        public static final int MAX = 25;
        public static final int VERIFICATION_PASSWORD = 26;
    }
}
